main() {
  //定义一个列表
  List<String> names = ["张三", "李四", "王五"];
  //定义一个数字列表
  List<int> numbers = [13, 21, 34, 47, 24, 59, 60, 73, 82, 91];

  //打印列表
  print(names);
  print(numbers);
  //遍历names
  for (String name in names) {
    print(name);
  }

  //对列表names进行操作
  names.add("赵六");
  print(names);
  names.remove("张三");
  print(names);
  names.clear();
  print(names);
  names.insert(0, "张三");
  print(names);

  //打印numbers的长度
  print(numbers.length);
  //打印numbers的第一个元素
  print(numbers[0]);
  //打印numbers的最后一个元素
  print(numbers[numbers.length - 1]);

  print("--------------------------------");
  //使用Foreach遍历numbers
  numbers.forEach((number) {
    print(number);
  });

  //数组操的方法
  //where
  List<int> evenNumbers = numbers.where((number) => number % 2 == 0).toList();
  print("evenNumbers:" + evenNumbers.toString());
  //map
  List<int> doubledNumbers = numbers.map((number) => number * 2).toList();
  print("doubledNumbers:" + doubledNumbers.toString());
  //reduce
  int sum = numbers.reduce((a, b) => a + b);
  print("sum:" + sum.toString());
  //forEach
  numbers.forEach((number) {
    print("number:" + number.toString());
  });
  //sort
  numbers.sort();
  print("sortedNumbers:" + numbers.toString());
}
